using System;
using System.Data;
using Oracle.ManagedDataAccess.Client;

namespace OracleInternal.Common
{
	internal class RefCursorInfo
	{
		internal string name = string.Empty;

		internal int position;

		internal ParameterDirection mode;

		internal bool isPrimaryKeyPresent;

		internal DataTable columnInfo = new DataTable("SchemaTable");

		internal RefCursorInfo()
		{
			columnInfo.Columns.Add("ColumnName", typeof(string));
			columnInfo.Columns.Add("ColumnOrdinal", typeof(int));
			columnInfo.Columns.Add("ColumnSize", typeof(int));
			columnInfo.Columns.Add("NumericPrecision", typeof(short));
			columnInfo.Columns.Add("NumericScale", typeof(short));
			columnInfo.Columns.Add("IsUnique", typeof(bool));
			columnInfo.Columns.Add("IsKey", typeof(bool));
			columnInfo.Columns.Add("IsRowID", typeof(bool));
			columnInfo.Columns.Add("BaseColumnName", typeof(string));
			columnInfo.Columns.Add("BaseSchemaName", typeof(string));
			columnInfo.Columns.Add("BaseTableName", typeof(string));
			columnInfo.Columns.Add("DataType", typeof(Type));
			columnInfo.Columns.Add("ProviderType", typeof(OracleDbType));
			columnInfo.Columns.Add("AllowDBNull", typeof(bool));
			columnInfo.Columns.Add("IsAliased", typeof(bool));
			columnInfo.Columns.Add("IsByteSemantic", typeof(bool));
			columnInfo.Columns.Add("IsExpression", typeof(bool));
			columnInfo.Columns.Add("IsHidden", typeof(bool));
			columnInfo.Columns.Add("IsReadOnly", typeof(bool));
			columnInfo.Columns.Add("IsLong", typeof(bool));
			columnInfo.Columns.Add("UdtTypeName", typeof(string));
			columnInfo.Columns.Add("IsAutoIncrement", typeof(bool));
			columnInfo.Columns.Add("IsIdentity", typeof(bool));
			columnInfo.Columns.Add("IdentityType", typeof(OracleIdentityType));
			columnInfo.Columns.Add("NativeDataType", typeof(string));
			columnInfo.Columns.Add("ProviderDBType", typeof(DbType));
			columnInfo.Columns.Add("ObjectName", typeof(string));
		}

		internal void FillMissingValuesFromMetadata(DataRow srcDataRow, DataRow targetDataRow)
		{
			for (int i = 0; i < targetDataRow.Table.Columns.Count; i++)
			{
				if (targetDataRow[i] == null || targetDataRow[i] == DBNull.Value)
				{
					string columnName = targetDataRow.Table.Columns[i].ToString();
					if (srcDataRow.Table.Columns.Contains(columnName))
					{
						targetDataRow[columnName] = srcDataRow[columnName];
					}
				}
			}
		}
	}
}
